package com.mini.mysql.service;

import com.mini.common.config.SpringCacheConfig;
import com.mini.mysql.model.BusinessTeacherInfo;
import com.mini.mysql.repository.BusinessTeacherInfoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author zl
 * @version 1.0
 * @date Created in 2019/12/9
 */
@Service
@Slf4j
public class BusinessTeacherInfoService {

    @Autowired
    private BusinessTeacherInfoRepository teacherInfoRepository;

    public List<BusinessTeacherInfo> findAll() {
        return teacherInfoRepository.findAll();
    }

    @Cacheable(value = SpringCacheConfig.TEACHER, key = "{#teacherId}")
    public BusinessTeacherInfo findByTeacherId(Long teacherId) {
        if (Objects.nonNull(teacherId) && teacherId == 0L) {
            return null;
        }
        return teacherInfoRepository.findByTeacherId(teacherId);
    }

    public List<BusinessTeacherInfo> findByUpdateTimeBetween(Date startTime, Date endTime) {
        return teacherInfoRepository.findByUpdateTimeBetweenOrderByUpdateTimeAsc(startTime, endTime);
    }

}
